package com.wn.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yellow Docter
 * @date 2023 -03-01
 * @desc
 *   测试
 *   生产端 通过 java 代码创建 交换机,队列
 *
 */
@Configuration
public class RabbitConfig {

    //写一个简单的 direct 交换机
    //01  创建队列
    @Bean(value = "queueA")
    public Queue queueA(){

        //创建一个队列  队列名称 是 QA
//        return QueueBuilder.durable("QA").build();
        Queue queue = new Queue("QA");
        return queue;
    }

    //02 创建叫交换机
    @Bean(name = "exchangeA")
    public Exchange exchangeA(){

        DirectExchange directExchange = new DirectExchange("exchange-a");
        return directExchange;
//        return ExchangeBuilder.directExchange("exchange-a").build();
    }

    //03 绑定
    @Bean
    public Binding binding(
            @Qualifier("queueA") Queue queue,
            @Qualifier("exchangeA")Exchange Exchange
    ){
//        return BindingBuilder.bind(queueA()).to(exchangeA()).with("zs").noargs();
        return BindingBuilder.bind(queue).to(Exchange).with("zs").noargs();
    }

}
